package com.ruoyi.common.utils;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class DigitsUtils {
    public static String calPercent(double numerator, double denominator) {
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);
        if(numerator<=0||denominator<=0){
            return "0";
        }
        return clearzero(df.format(numerator / denominator * 100.00));
    }

    public static String avgPercent(double numerator, double denominator) {
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);
        if(numerator<=0||denominator<=0){
            return "0";
        }
        return clearzero(df.format(numerator / denominator));
    }

    public static String clearzero(String str) {
        return str.replace(",", "");
    }
}
